package com.zhipu.resetbalance.ui.home.system.bh.adapter;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.TimeUtils;
import com.zhipu.resetbalance.R;
import com.zhipu.resetbalance.databinding.ItemPersonnlBinding;
import com.zhipu.resetbalance.listener.ChooseClickCallback;
import com.zhipu.resetbalance.mobile.event.NumberedEntity;

import java.util.List;

public class NumberManagementAdapter extends RecyclerView.Adapter<NumberManagementAdapter.ItemViewHolder>{

    /**
     * 数据
     */
    private List<NumberedEntity> numberedEntityList;
    public List<NumberedEntity> getNumberedEntityList() {
        return numberedEntityList;
    }

    public void setNumberedEntityList(List<NumberedEntity> numberedEntityList) {
        this.numberedEntityList = numberedEntityList;
        notifyDataSetChanged();
    }


    private ChooseClickCallback mChooseClickCallback;
    public void setChooseClickCallback(ChooseClickCallback mChooseClickCallback) {
        this.mChooseClickCallback = mChooseClickCallback;
    }

    @NonNull
    @Override
    public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemPersonnlBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_personnl, parent, false);
        return new ItemViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull ItemViewHolder holder, @SuppressLint("RecyclerView") int position) {
        NumberedEntity mNumberedEntity = numberedEntityList.get(position);
        if(null != mNumberedEntity){
            //
            holder.binding.inspectionPersonnelId.setText((position + 1) + "");
            //
            holder.binding.name.setText(mNumberedEntity.NumberedName);
            //
            holder.binding.establish.setText(TimeUtils.millis2String(mNumberedEntity.creationTime));
            //
            holder.binding.selectCheckBox.setChecked(mNumberedEntity.select);
            //
            holder.binding.Personnel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(null != mChooseClickCallback){
                        mChooseClickCallback.onChooseClickCallback(position);
                    }
                }
            });
        }
    }


    @Override
    public int getItemCount() {

        return null == numberedEntityList ? 0 : numberedEntityList.size();
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemPersonnlBinding binding;
        public ItemViewHolder(@NonNull ItemPersonnlBinding mItemPersonnlBinding) {
            super(mItemPersonnlBinding.getRoot());
            this.binding = mItemPersonnlBinding;
        }
    }
}
